package com.co.server.dao.vote.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.co.common.dao.BaseDaoImpl;
import com.co.common.exception.DaoException;
import com.co.server.dao.vote.TVoteDao;
import com.co.server.entity.user.aide.TUsersConstant;
import com.co.server.entity.vote.TVote;
import com.co.server.entity.vote.TVoteUser;

@Repository
public class TVoteDaoImpl extends BaseDaoImpl<TVote, Integer> implements TVoteDao {

	private static final String SELECT_NOT_VOTE_BY_USER_ID_AND_IP = "selectNotVoteByUserIdandIp";
	
	public List<TVote> selectNotVoteByUserIdandIp(Integer userId,String voteIp) {
		Assert.notNull(userId);
		Assert.notNull(voteIp);
		TVoteUser tVoteUser = new TVoteUser();
		tVoteUser.setUserId(userId);
		//游客身份可以不同ip多次投票
		if(userId ==TUsersConstant.USER_GUEST_ID){
			tVoteUser.setVoteIp(voteIp);
		}
		try {
			return this.sqlSession.selectList(getSqlName(SELECT_NOT_VOTE_BY_USER_ID_AND_IP), tVoteUser);
		} catch (Exception e) {
			throw new DaoException(String.format("根据ID查询对象出错！语句：%s", getSqlName(SELECT_NOT_VOTE_BY_USER_ID_AND_IP)), e);
		}
	}
	

}